package com.admin.business.transitionWord;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 业主委员会换届相关文件
 * @create: 2023-10-13 09:55:57
 **/
@Service("transitionWordService")
@Slf4j
public class TransitionWordService{

    @Resource
    TransitionWordDao transitionWordDao;

    /**
     * 添加业主委员会换届相关文件,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - community_id:业委会换届申请记录id
     *                   - file_path:文件路径
     *                   - file_name:文件名称
     *                   - file_img:线下公示图片路径
     *                   - file_agree:同意票数
     *                   - file_no:不同意票数
     *                   - begin_time:创建时间
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return addTransitionWord(CDO cdoRequest) {
        transitionWordDao.addTransitionWord(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新业主委员会换届相关文件数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - community_id:业委会换届申请记录id
     *                   - file_path:文件路径
     *                   - file_name:文件名称
     *                   - file_img:线下公示图片路径
     *                   - file_agree:同意票数
     *                   - file_no:不同意票数
     *                   - begin_time:创建时间
     *                   - update_time:更新时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return updateTransitionWordById(CDO cdoRequest) {
        transitionWordDao.updateTransitionWordById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除业主委员会换届相关文件数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return deleteTransitionWordById(CDO cdoRequest){
        int count = transitionWordDao.deleteTransitionWordById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除业主委员会换届相关文件数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return deleteTransitionWord(CDO cdoRequest) {
        int count = transitionWordDao.deleteTransitionWord(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取业主委员会换届相关文件数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return getTransitionWordById(CDO cdoRequest) {
        CDO cdoMapperResult = transitionWordDao.getTransitionWordById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取业主委员会换届相关文件数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return getTransitionWordListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = transitionWordDao.getTransitionWordListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = transitionWordDao.getTransitionWordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取业主委员会换届相关文件数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return getTransitionWordListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = transitionWordDao.getTransitionWordListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = transitionWordDao.getTransitionWordCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
